﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../Content/js/angular1.2.13.js"></script>
</head>
<body ng-app="myApp" ng-controller="MyController">
    <div>
        <input type="text" ng-model="expr" placeholder="Enter an expression" />
        <h2>{{parsedValue}}</h2>
    </div>
    <script>
        angular.module('myApp', [])
        .controller('MyController', function ($scope, $parse) {
            $scope.$watch('expr', function (newVal, oldVal, scope) {
                if (newVal != oldVal) {
                    //用该表达式设置parseFun
                    var parseFun = $parse(newVal);
                    //获取经过解析后表达式的值
                    $scope.parsedValue = parseFun(scope);
                }
            })
        })
    </script>
</body>
</html>
